package cn.wangxl.group.rpc.register;

import cn.wangxl.group.rpc.protocol.Protocol;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @Description DefaultServiceRegister
 * @Classname DefaultServiceRegister
 * @Created by wangxl
 * @Date 2020/9/22 22:41
 */
public class DefaultServiceRegister implements ServiceRegister {

    private Map<String, ServiceObject> serviceMap = new HashMap<>();


    @Override
    public void register(ServiceObject serviceObject, Protocol protocol, int port) throws Exception {
        Objects.requireNonNull(serviceObject,"参数不能为空");
        Objects.requireNonNull(protocol,"参数不能为空");
        if(port<=0 || port>65535){
            throw new RuntimeException("不可用的端口");
        }
        this.serviceMap.put(serviceObject.getName(),serviceObject);
    }

    @Override
    public ServiceObject getServiceObject(String name) {
        return this.serviceMap.get(name);
    }
}
